package com.ruoyi.common.enums.wecom;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum WecomChatGroupUpdateTypeEnum {
    ADD_MEMBER("add_member", "成员入群"),
    DEL_MEMBER("del_member", "成员退群"),
    CHANGE_OWNER("change_owner", "群主变更"),
    CHANGE_NAME("change_name", "群名变更"),
    CHANGE_NOTICE("change_notice", "群公告变更");

    private final String code;
    private final String desc;


    private static final Map<String, WecomChatGroupUpdateTypeEnum> ENUM_MAP;

    static {
        WecomChatGroupUpdateTypeEnum[] values = values();
        Map<String, WecomChatGroupUpdateTypeEnum> enToCn = new HashMap<>(values.length);
        for (WecomChatGroupUpdateTypeEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static WecomChatGroupUpdateTypeEnum getEnumByType(String type) {
        WecomChatGroupUpdateTypeEnum wecomChatGroupUpdateTypeEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(wecomChatGroupUpdateTypeEnum)) {
            throw new RuntimeException("类型有误");
        }
        return wecomChatGroupUpdateTypeEnum;
    }
}
